package com.xgd.phylw.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xgd.phylw.bean.*;
import com.xgd.phylw.service.BackPageService;
import com.xgd.phylw.service.HallService;
import com.xgd.phylw.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class BackPageController {
    @Autowired
    private BackPageService backPageService;
    @Autowired
    private MovieService movieService;
    @Autowired
    private HallService hallService;

    @RequestMapping("Users")
    public String PageChangeToUsers(Model model,@RequestParam(value = "pageSize",required = false,defaultValue = "5") int pageSize
            ,@RequestParam(value = "pageNum",required = false,defaultValue = "1") int pageNum){

        Page<Object> objectPage = PageHelper.startPage(pageNum,pageSize);
        List<Member> members = backPageService.SelectAllMember();

        model.addAttribute("pages",objectPage.toPageInfo());
        model.addAttribute("members",members);
        return "users";
    }
    @RequestMapping("Order")
    public String PageChangeToOrder(Model model,@RequestParam(value = "pageSize",required = false,defaultValue = "6") int pageSize
            ,@RequestParam(value = "pageNum",required = false,defaultValue = "1") int pageNum){

        Page<Object> objectPage = PageHelper.startPage(pageNum,pageSize);
        List<Orderd> orderds = backPageService.SelectAllOrderd();

        model.addAttribute("pages",objectPage.toPageInfo());
        model.addAttribute("orderds",orderds);
        return "order";
    }
    @RequestMapping("AdminMovie")
    public String PageChangeToAdminMovie(Model model,@RequestParam(value = "pageSize",required = false,defaultValue = "4") int pageSize
            ,@RequestParam(value = "pageNum",required = false,defaultValue = "1") int pageNum){

        Page<Object> objectPage = PageHelper.startPage(pageNum,pageSize);
        List<Movie> movies = backPageService.SelectAllMovie();
        System.out.println(movies.size());
        model.addAttribute("pages",objectPage.toPageInfo());
        model.addAttribute("movies",movies);
        return "admin_movie";
    }
    @RequestMapping("AdminSeat")
    public String PageChangeToAdminSeat(Model model){
        List<Schedule> schedules = backPageService.SelectAllSchedule();
        model.addAttribute("schedules",schedules);
        for(Schedule schedule:schedules){
            System.out.println(schedule);
        }
        return "admin_seat";
    }
    @RequestMapping("MovieType")
    public String PageChangeToMovieType(Model model,@RequestParam(value = "pageSize",required = false,defaultValue = "12") int pageSize
            ,@RequestParam(value = "pageNum",required = false,defaultValue = "1") int pageNum){

        Page<Object> objectPage = PageHelper.startPage(pageNum, pageSize);
        List<Movie> movieList = backPageService.SelectAllMovieTemp();

        model.addAttribute("pages",objectPage.toPageInfo());
        model.addAttribute("movieTemp",movieList);
        return "movie_type";
    }
    //跳转页面
    @RequestMapping("Customer")
    public String PageChangeToCustomer(Model model){
        return "customer";
    }
    @RequestMapping("UserAdd")
    public String PageChangeToUsersAdd(Model model){
        return "users_add";
    }
    @RequestMapping("MovieAdd")
    public String PageChangeToMovieAdd(Model model){
        return "movie_add";
    }
    @RequestMapping("OrderAdd")
    public String PageChangeToOrderAdd(Model model){
        return "order_add";
    }
    @RequestMapping("OrderUpdate")
    public String PageChangeToOrderUpdate(Model model){
        return "order_update";
    }
    @RequestMapping("StudioUpdate")
    public String PageChangeToStudioUpdate(Integer hallId,Model model){
        Hall hall = hallService.selectByPrimaryKey(hallId);
        model.addAttribute("hall",hall);
        return "studio_update";
    }
    @RequestMapping("StudioAdd")
    public String PageChangeToStudioAdd(Model model){
        return "studio_add";
    }
    @RequestMapping("TypeAdd")
    public String PageChangeToTypeAdd(Model model){
        List<Movie> movies = backPageService.SelectAllMovieName();
        model.addAttribute("movieName", movies);
        return "type_add";
    }
    @RequestMapping("adminSeatAdd")
    public String PageChangeToAdminSeatUpdate(Model model){
        List<Movie> movies = movieService.selectMovie();
        List<Hall> halls = hallService.SelectAllHall();
        model.addAttribute("movies",movies);
        model.addAttribute("halls",halls);
        return "admin_seat_add";
    }
}
